/*
 * @(#)OtherIdentifierTransformer.java
 * Date 2013-08-17
 * Version 1.0
 * Author Jim Horner
 * Copyright (c)2012
 */


package us.hornerscorners.lamppost.pix.transformer;

import javax.enterprise.context.ApplicationScoped;

import javax.inject.Inject;

import org.hl7.v3.PRPAMT201301UV02OtherIDs;

import us.hornerscorners.lamppost.exception.ServiceActionException;

import us.hornerscorners.lamppost.hl7v3common.utils.HL7Utils;

import us.hornerscorners.lamppost.model.patient.OtherIdentifier;

import us.hornerscorners.lamppost.transformer.AbstractTransformer;


/**
 *
 * @author jim
 */
@ApplicationScoped
public class OtherIdentifierTransformer
        extends AbstractTransformer<PRPAMT201301UV02OtherIDs, OtherIdentifier> {

    /** Field description */
    @Inject
    private InstanceIdentifierTransformer instanceIdentifierTransformer;

    /** Field description */
    @Inject
    private OrganizationTransformer organizationTransformer;

    /**
     * Method description
     *
     *
     * @param prpaOtherId
     *
     * @return
     */
    @Override
    public OtherIdentifier transform(PRPAMT201301UV02OtherIDs prpaOtherId)
            throws ServiceActionException {

        OtherIdentifier result = null;

        if (prpaOtherId != null) {

            result = new OtherIdentifier();

            result.setTypeCode(HL7Utils.parseFirstString(prpaOtherId.getClassCode()));

            result.getIdentifiers().addAll(
                this.instanceIdentifierTransformer.transform(prpaOtherId.getId()));

            result.setScopingOrganization(
                this.organizationTransformer.transform(
                    prpaOtherId.getScopingOrganization()));
        }

        return result;
    }
}
